# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="Administrator"
__date__ ="$2011-10-11 16:50:46$"

if __name__ == "__main__":
    n,m = raw_input().split();
    n = int(n); m = int(m);
    ans = -1;
    pos = 0;
    mp = [];
    end = 1;
    for i in range(n):
        mp.append(raw_input());
        if mp[i].find('W') != -1:
            end = i + 1;
    for row in range(end):
        ans += 1;
        line  = mp[row];
        left = line.find('W');
        if left == -1:
            continue;
        right = line.rfind('W');
        if row&1 :
            if pos < right:
                ans += right - pos;
                pos = right;
            ans += pos - left;
            pos = left;
        else:
            if pos > left:
                ans += pos - left;
                pos = left;
            ans += right - pos;
            pos = right
    print ans;


